var app = $("#input-app").val();
var icon = $("#input-icon").val();
var twoDimentCode = $("#input-twodimentcode").val();
var screenshots = $.parseJSON($("#input-screenshots").val());

function deleteApp() {
	$("#input-app").val("");
	$("#show-app").html("");
	$("#toggle-app").hide();
	$("#upload-app").show();
}
function deleteIcon() {
	$("#input-icon").val("");
	$("#show-icon").html("");
	$("#toggle-icon").hide();
	$("#upload-icon").show();
}
function deleteTwodimentcode() {
	$("#input-twodimentcode").val("");
	$("#show-twodimentcode").html("");
	$("#toggle-twodimentcode").hide();
	$("#upload-twodimentcode").show();
}
function deleteScreenshot(ss) {
	for ( var index in screenshots) {
		if (ss == screenshots[index]) {
			screenshots.splice(index, 1);
			break;
		}
	}
	$("#input-screenshots").val(JSON.stringify(screenshots));
	var event = window.event;
	$(event.target.parentElement).remove();
}

function appUploaded(appName, appPath) {
	$("#show-app").append($("<div>" + appName + "</div>"));
	app = appPath;
	$("#input-app").val(app);
	$("#toggle-app").show();
	$("#upload-app").hide();
}
function iconUploaded(imageName, imagePath) {
	$("#show-icon").append($("<div>" + imageName + "</div>"));
	icon = imagePath;
	$("#input-icon").val(icon);
	$("#toggle-app").show();
	$("#upload-icon").hide();
}
function twoDimentCodeUploaded(imageName, imagePath) {
	$("#show-twodimentcode").append($("<div>" + imageName + "</div>"));
	twoDimentCode = imagePath;
	$("#input-twodimentcode").val(twoDimentCode);
	$("#toggle-twodimentcode").show();
	$("#upload-twodimentcode").hide();
}
function screenshotUploaded(imageName, imagePath) {
	var screenshot = "<div>";
	screenshot += "<a style=\"cursor: pointer;\" onclick=\"preview('.."
			+ imagePath + "')\">预览</a>";
	screenshot += "<a class=\"delete\" onclick=\"deleteScreenshot('"
			+ imagePath + "')\">删除</a>";
	screenshot += "</div>";
	$("#show-scrennshots").append($(screenshot));
	screenshots.push(imagePath);
	$("#input-screenshots").val(JSON.stringify(screenshots));
}
function preview(url) {
	$("#preview-image").find(".preview").attr("src", url);
	$("#preview-image").show();
}
function closePreview() {
	$("#preview-image").hide();
}